version 11.1
#delimit;
clear;
set more off;
version 11.1;
  quietly log;
  local logon = r(status);
  if "`logon'" == "on" {; log close; };
log using EPS_replication.log, text replace;

/********************************************/
/*  Mark David Nieman and Jon Ring     */
/*  15/08/2015                               */
/*  Human Rights Instrument and Replication  */
/*	Output: Table 1, 2, 3				*/
/*  Stata 11.1                              */
/********************************************/
#delimit;
clear; clear matrix;
program drop _all;
set seed 2014;
set memory 4g;

#delimit;
use HRmeasure_rep.dta, replace;

#delimit;
xtset ccode year;
tab region, gen(reg);

#delimit;
/* OLS  */
reg difference coldwar polity2 us_ally_hier  prop_UStrade if year>1979;
estimates store reg_no;
/* OLS with time trend */
reg difference coldwar polity2 us_ally_hier  prop_UStrade t t2 t3 if year>1979;
estimates store reg_time;
/* OLS with lag*/
reg difference coldwar polity2 us_ally_hier  prop_UStrade t t2 t3 L.difference if year>1979;
estimates store reg_time_lag;
/* OLS with regions */
reg difference coldwar polity2 us_ally_hier  prop_UStrade t t2 t3 L.difference reg1  reg3 reg4 reg5 reg6 reg7 if year>1979;
estimates store reg_region;

/* Ordered logit*/
ologit difference coldwar polity2 us_ally_hier  prop_UStrade if year>1979;
estimates store olog_no;
/* Ordered logit with time */
ologit difference coldwar polity2 us_ally_hier  prop_UStrade t t2 t3 if year>1979;
estimates store olog_time;
/* Oredered logit with lag*/
tab difference, gen(diff);
ologit difference coldwar polity2 us_ally_hier  prop_UStrade t t2 t3 L.diff1 L.diff2 L.diff3 L.diff4 L.diff5 L.diff6 if year>1979;
estimates store olog_time_lag;
/* Ordered logit with regions */
ologit difference coldwar polity2 us_ally_hier  prop_UStrade t t2 t3 L.diff1 L.diff2 L.diff3 L.diff4 L.diff5 L.diff6 reg1  reg3 reg4 reg5 reg6 reg7 if year>1979;
estimates store olog_region;

#delimit;
estout reg_no reg_time reg_time_lag reg_region olog_no olog_time olog_time_lag olog_region
		, replace style(tex)
	stats(r2 F ll N )
	cells(b(fmt(3) star) se(par))
	modelwidth(8)
	starlevels(* 0.1 ** 0.05 *** 0.01) legend
	varwidth(15)
	order(coldwar polity2 us_ally_hier prop_UStrade t t2 t3 
	reg1  reg3 reg4 reg5 reg6 reg7 _cons)
	collabels(, none)
	varlabels(
	coldwar "Cold War" 
	polity2 "Democracy"
	us_ally_hier "US Ally Embed."
	/*UStrade_dep "US Trade Depen." */ 
	prop_UStrade "Prop. US Trade"
	t "Time" 
	t2 "Time^2" 
	t3 "Time^3"
	L.difference "Lagged Bias"
	reg1 "Americas"
	reg3 "East Europe" 
	reg4 "Africa" 
	reg5 "Middle East" 
	reg6 "Asia"
	reg7 "Oceania" 
	_cons "Constant"
	);

	
/* Replication Thorian Wright 2014*/
#delimit;
ologit ainew  terrrev fatality terrXfatality   lpop_lag lgdppc_lag  civconflict nonfatal dem_lag ai1 ai2 ai3 ai4 , cluster(ccode);
estimates store Wright_rep_o_all;
#delimit;
ologit ainew  terrrev fatality terrXfatality lpop_lag lgdppc_lag  civconflict nonfatal ai1 ai2 ai3 ai4 if (dem_lag==1) ,  cluster(ccode);
estimates store Wright_rep_o_dem;
#delimit;
ologit ainew  terrrev fatality terrXfatality lpop_lag lgdppc_lag  civconflict nonfatal ai1 ai2 ai3 ai4 if (dem_lag==0),  cluster(ccode);
estimates store Wright_rep_o_auto;


#delimit; 
/* Replication Thorian Wright 2014 on post-1979 sample */
ologit ainew  terrrev fatality terrXfatality   lpop_lag lgdppc_lag  civconflict nonfatal dem_lag ai1 ai2 ai3 ai4 if year>1980 &  _est_Wright_rep_o_all==1;
estimates store Wright_s_o_all;
ologit ainew  terrrev fatality terrXfatality lpop_lag lgdppc_lag  civconflict nonfatal ai1 ai2 ai3 ai4 if (dem_lag==1) & year>1980 &  _est_Wright_rep_o_all==1;
estimates store Wright_s_o_dem;
ologit ainew  terrrev fatality terrXfatality lpop_lag lgdppc_lag  civconflict nonfatal ai1 ai2 ai3 ai4 if (dem_lag==0) & year>1980 &  _est_Wright_rep_o_all==1;
estimates store Wright_s_o_auto;


/* Use IV only if AI is missing and SD is used */
#delimit;
ologit IVmiss  terrrev fatality terrXfatality   lpop_lag lgdppc_lag  civconflict nonfatal dem_lag IVmiss_1 IVmiss_2 IVmiss_3 IVmiss_4 if _est_Wright_rep_o_all==1, vce(bootstrap, reps(100) reject(e(converged)==0));
estimates store Wright_ivmiss_o_all;
#delimit;
ologit IVmiss  terrrev fatality terrXfatality   lpop_lag lgdppc_lag  civconflict nonfatal IVmiss_1 IVmiss_2 IVmiss_3 IVmiss_4 if (dem_lag==1) &  _est_Wright_rep_o_all==1, vce(bootstrap, reps(100) reject(e(converged)==0));
estimates store Wright_ivmiss_o_dem;
#delimit;
ologit IVmiss  terrrev fatality terrXfatality   lpop_lag lgdppc_lag  civconflict nonfatal IVmiss_1 IVmiss_2 IVmiss_3 IVmiss_4 if (dem_lag==0) &  _est_Wright_rep_o_all==1, vce(bootstrap, reps(100) reject(e(converged)==0));
estimates store Wright_ivmiss_o_auto;

/* Use IV only if AI is missing and SD is used and post-1979*/
#delimit;
ologit IVmiss  terrrev fatality terrXfatality   lpop_lag lgdppc_lag  civconflict nonfatal dem_lag IVmiss_1 IVmiss_2 IVmiss_3 IVmiss_4 if year>1980 & _est_Wright_rep_o_all==1, vce(bootstrap, reps(100) reject(e(converged)==0));
estimates store Wright_ivmiss_s_all;
#delimit;
ologit IVmiss  terrrev fatality terrXfatality   lpop_lag lgdppc_lag  civconflict nonfatal IVmiss_1 IVmiss_2 IVmiss_3 IVmiss_4 if (dem_lag==1) & year>1980 & _est_Wright_rep_o_all==1, vce(bootstrap, reps(100) reject(e(converged)==0));
estimates store Wright_ivmiss_s_dem;
#delimit;
ologit IVmiss  terrrev fatality terrXfatality   lpop_lag lgdppc_lag  civconflict nonfatal IVmiss_1 IVmiss_2 IVmiss_3 IVmiss_4 if (dem_lag==0) & year>1980 & _est_Wright_rep_o_all==1, vce(bootstrap, reps(100) reject(e(converged)==0));
estimates store Wright_ivmiss_s_auto;


#delimit;
estout Wright_rep_o_all Wright_rep_o_dem Wright_rep_o_auto 
		Wright_s_o_all Wright_s_o_dem  Wright_s_o_auto 
		, replace style(tex)
	stats(r2 ll N )
	cells(b(fmt(3) star) se(par))
	modelwidth(8)
	starlevels(* 0.1 ** 0.05 *** 0.01) legend
	varwidth(15)
	order(terrrev fatality terrXfatality   lpop_lag lgdppc_lag  civconflict nonfatal dem_lag ai1 ai2 ai3 ai4)
	collabels(, none)
	varlabels(
terrrev "Territorial revisionist"
fatality "MID fatalities (max/year)"
terrXfatality  "Terr. rev. X fatalities" 
lpop_lag "Population (ln, t-1)"
lgdppc_lag  "Econ. development (ln, t-1)"
civconflict "Civil conflict"
nonfatal "Non-fatal MID"
dem_lag "Democracy (t-1)"
ai1 "lag ai1"
ai2 "lag ai2"
ai3 "lag ai3"
ai4 "lag ai4"
_cons "Constant"
	);

#delimit;
estout Wright_ivmiss_o_all Wright_ivmiss_o_dem Wright_ivmiss_o_auto
		Wright_ivmiss_s_all Wright_ivmiss_s_dem Wright_ivmiss_s_auto
		, replace style(tex)
	stats(r2 ll N )
	cells(b(fmt(3) star) se(par))
	modelwidth(8)
	starlevels(* 0.1 ** 0.05 *** 0.01) legend
	varwidth(15)
	order(terrrev fatality terrXfatality   lpop_lag lgdppc_lag  civconflict nonfatal dem_lag IVmiss_1 IVmiss_2 IVmiss_3 IVmiss_4)
	collabels(, none)
	varlabels(
terrrev "Territorial revisionist"
fatality "MID fatalities (max/year)"
terrXfatality  "Terr. rev. X fatalities" 
lpop_lag "Population (ln, t-1)"
lgdppc_lag  "Econ. development (ln, t-1)"
civconflict "Civil conflict"
nonfatal "Non-fatal MID"
dem_lag "Democracy (t-1)"
IVmiss_1 "lag iv1"
IVmiss_2 "lag iv2"
IVmiss_3 "lag iv3"
IVmiss_4 "lag iv4"
_cons "Constant"
	);	

	
log close;	 
